var id = getUrlParam('id');
layui.use(['element','layer','table','dtree'],  function () {
    form = layui.form;
    layer = layui.layer;
    axios.get(ctx + 'dept/info/' + id).then(function (res) {
        console.log(res);
        $('.wrapper').html(
            '<div class="layui-form-item">'
            +  '<label class="layui-form-label">处室名称</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="department" autocomplete="off" placeholder="处室名称" class="layui-input" value="' + res.data.data.department + '">'
            +  '</div>'
            +  '</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">部门编号</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="deptId" autocomplete="off" placeholder="部门编号" class="layui-input" value="' + res.data.data.deptId + '">'
            +  '</div>'
            +'</div>'
            +'<div class="layui-form-item">'
            +  '<label class="layui-form-label">排序号</label>'
            +  '<div class="layui-input-block">'
            +      '<input type="text" name="sortIndex" autocomplete="off" placeholder="排序号" class="layui-input" value="' + res.data.data.sortIndex + '">'
            +  '</div>'
            +'</div>'
        );
        form.render();
    })

    form.on('submit(add)', function (data) {
        console.log(data.field);
        data.field['id'] = id;
        axios.post(ctx + 'dept/update', data.field).then(function (res) {
            if(res.data.code == 0) {
                layer.msg('保存成功');
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
                parent.table.reload();
            }else {
                layer.msg('保存失败');
            }
        }).catch(function (err) {
            console.log(err);
        });
        return false;
    });
});

$('#cancel').click(function () {
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index);
});